package com.xiaohe66.web.gateway.http.im;

import com.xiaohe66.common.value.R;
import com.xiaohe66.web.application.im.MessageAppService;
import com.xiaohe66.web.application.im.bo.ListUnreadMessageDigestBo;
import com.xiaohe66.web.application.im.bo.MessageAddBo;
import com.xiaohe66.web.application.im.bo.MessageListBo;
import com.xiaohe66.web.application.im.result.MessageListUnreadDigestResult;
import com.xiaohe66.web.application.im.result.MessageResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaohe
 * @since 2023.08.10 13:59
 */
@RestController
@RequestMapping("/im/message")
@RequiredArgsConstructor
public class MessageController {

    private final MessageAppService messageAppService;

    @PostMapping
    public R<Object> sendMessage(@RequestBody MessageAddBo bo) {
        messageAppService.addMessage(bo);
        return R.ok();
    }

    @GetMapping("/unread")
    public R<List<MessageListUnreadDigestResult>> list(ListUnreadMessageDigestBo bo) {
        return R.ok(messageAppService.listUnreadMessageDigest(bo));
    }

    @GetMapping("/list")
    public R<List<MessageResult>> list(MessageListBo bo) {
        return R.ok(messageAppService.list(bo));
    }

}
